package es.udc.pfc.davidparedes.web.components;

import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Cookies;

import es.udc.pfc.davidparedes.model.util.GlobalNames;
import es.udc.pfc.davidparedes.web.pages.Index;
import es.udc.pfc.davidparedes.web.services.AuthenticationPolicy;
import es.udc.pfc.davidparedes.web.services.AuthenticationPolicyType;
import es.udc.pfc.davidparedes.web.util.CookiesManager;
import es.udc.pfc.davidparedes.web.util.UserSession;

public class BootstrapLayout {
    @Property
    @Parameter(required = false, defaultPrefix = "message")
    private String menuExplanation;

    @Property
    @Parameter(required = true, defaultPrefix = "message")
    private String pageTitle;

    @Property
    @SessionState(create=false)
    private UserSession userSession;

    @Inject
    private Cookies cookies;

    @AuthenticationPolicy(AuthenticationPolicyType.AUTHENTICATED_USERS)
   	Object onActionFromLogout() {
        userSession = null;
        CookiesManager.removeCookies(cookies);
        return Index.class;
	}
    
   	public boolean isVendor() {
   		if (userSession.getUserType().equals(GlobalNames.USER_TYPE_VENDOR)) {
   			return true;
   		}
        return false;
	}
   	
   	public boolean isManager() {
   		if (userSession.getUserType().equals(GlobalNames.USER_TYPE_UNIVERSE_MANAGER)) {
   			return true;
   		}
        return false;
	}
   	
   	public boolean isDirector() {
   		if (userSession.getUserType().equals(GlobalNames.USER_TYPE_DIRECTOR)) {
   			return true;
   		}
        return false;
	}
   	
   	public boolean isAdmin() {
   		if (userSession.getUserType().equals(GlobalNames.USER_TYPE_ADMIN)) {
   			return true;
   		}
        return false;
	}
    
}